<?php

/**
 *
 * This file is a subject under proprietary sofrware license
 * 
 * @category
 * @package
 * @subpackage
 * @author      valerii lazarevych <lazarevuch@gmail.com>
 * @copyright   Copyright(c) Valerii Lazarevych
 * @license     proprietary software license
 * @version     $Id: IndexController.php 29.09.2012 18:27:33 valerii $
 */

/**
 * Class IndexController
 * 
 * Contains functions to administer the news
 */
class IndexController extends Zend_Controller_Action
{ 
    /**
     * Default action
     * 
     * Get news list 
     */
    public function indexAction()
    {                
        $newsModel              =   new models_News();        
        
        $newsPaginator          =   Zend_Paginator::factory($newsModel->newsList());
        $newsPaginator->setCurrentPageNumber($this->_getParam('pageId'));                
        
        $this->view->newsList   =   $newsPaginator->getCurrentItems();
        $this->view->paginator  =   $newsPaginator->getPages();                
    }
    
    /**
     * News edit action
     * 
     * Add or edit a news 
     */
    public function editnewsAction()
    {                                        
        $news   = new domainObjects_News;            
        $news->find($this->_getParam('id'));                        
        $this->view->editNews   =   $news;                   
    }
            
    /**
     * Save news action
     * 
     * Save changed or a new news 
     */                                   
    public function savenewsAction()
    {                
        // build news object from request
        $news   = new domainObjects_News;
        $news->build( $this->_getAllParams() );
        
        // save its
        $news->save();
        
        // go to news list
        $this->_redirect('/news');   //$this->_forward('index');
    }

    /**
     * News delete action
     * 
     * Delte a news 
     */
    public function deletenewsAction()
    {
        // get news object to delete
        $news   = new domainObjects_News;
        $news->find($this->_getParam('id'));
        
        // remove its
        $news->remove();
        
        // go to news list
        $this->_redirect('/news');
    }
}
